﻿<Window x:Class="ThePingMasterConfiguration.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Validation="clr-namespace:ThePingMasterConfiguration.Validation"
        xmlns:ViewModels="clr-namespace:ThePingMasterConfiguration.ViewModels"
        Title="The Ping Master Configuration" Height="421" Width="525">
    <Window.DataContext>
        <ViewModels:ConfigurationModel />
    </Window.DataContext>
    <Window.Resources>
        <Style x:Key="ValidatingTextBox" TargetType="TextBox">
            <Setter Property="Margin" Value="4" />
            <Style.Triggers>
                <Trigger Property="Validation.HasError" Value="true">
                    <Setter Property="Background" Value="Red" />
                    <Setter Property="Foreground" Value="#cccccc" />
                </Trigger>
            </Style.Triggers>            
        </Style>
    </Window.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Column="0" Grid.Row="0">Test Interval (seconds)</TextBlock>
        <TextBox Grid.Column="1" Grid.Row="0" Style="{StaticResource ValidatingTextBox}">
            <TextBox.Text>
                <Binding Path="Interval">
                    <Binding.ValidationRules>
                        <Validation:IntegerValidationRule Min="1" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
        
        <TextBlock Grid.Column="0" Grid.Row="1">Timeout (seconds)</TextBlock>
        <TextBox Grid.Column="1" Grid.Row="1" Style="{StaticResource ValidatingTextBox}">
            <TextBox.Text>
                <Binding Path="Timeout">
                    <Binding.ValidationRules>
                        <Validation:IntegerValidationRule Min="1" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
        
        <TextBlock Grid.Column="0" Grid.Row="2">Retry attempts before failure</TextBlock>
        <TextBox Grid.Column="1" Grid.Row="2" Style="{StaticResource ValidatingTextBox}" x:Name="Root">
            <TextBox.Text>
                <Binding Path="RetryAttemptsBeforeFailure">
                    <Binding.ValidationRules>
                        <Validation:IntegerValidationRule Min="1" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
        
        <TextBlock Grid.Column="0" Grid.Row="3">Retry on network exception</TextBlock>
        <CheckBox Grid.Column="1" Grid.Row="3" IsChecked="{Binding RetryOnNetworkException}" />        
                
        <TextBlock Grid.Column="0" Grid.Row="4">Success Command</TextBlock>
        <Grid Grid.Column="1" Grid.Row="4">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBox Grid.Column="0" Text="{Binding Path=OnSuccess}" />
            <Button Grid.Column="1" Command="{Binding BrowseSuccessCommand}">
                <TextBlock Margin="0">...</TextBlock>
            </Button>
        </Grid>
        
        <TextBlock Grid.Column="0" Grid.Row="5">Success Command Parameters</TextBlock>
        <TextBox Grid.Column="1" Grid.Row="5" Text="{Binding Path=OnSuccessParams}" />

        <TextBlock Grid.Column="0" Grid.Row="6">Failure Command</TextBlock>
        <Grid Grid.Column="1" Grid.Row="6">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <TextBox Grid.Column="0" Text="{Binding Path=OnFailure}" />
            <Button Grid.Column="1" Command="{Binding BrowseFailureCommand}">
                <TextBlock Margin="0">...</TextBlock>
            </Button>
        </Grid>
        <TextBlock Grid.Column="0" Grid.Row="7">Failure Command Parameters</TextBlock>
        <TextBox Grid.Column="1" Grid.Row="7" Text="{Binding Path=OnFailureParams}" />

        <Grid Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="8">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <ListBox Grid.Column="0" ItemsSource="{Binding Path=Addresses}" SelectedItem="{Binding Path=SelectedAddress, Mode=OneWayToSource}" >
            
            </ListBox>
            <StackPanel Grid.Column="1" Orientation="Vertical">
                <Button Style="{StaticResource ActionButton}" Content="Add" Command="{Binding AddAddressCommand}" />
                <Button Style="{StaticResource ActionButton}" Content="Remove" Command="{Binding RemoveAddressCommand}" />
            </StackPanel>
        </Grid>
        
        <StackPanel Orientation="Horizontal" Grid.Column="0" Grid.Row="9">
            <Button Style="{StaticResource ActionButton}" Content="About" Command="{Binding AboutCommand}" />
        </StackPanel>
        <StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="9" HorizontalAlignment="Right">
            <Button Style="{StaticResource ActionButton}" Content="Close" Command="{Binding Path=QuitCommand}"  />
            <Button Style="{StaticResource ActionButton}" Content="Save" Command="{Binding Path=SaveCommand}" />
        </StackPanel>
    </Grid>
</Window>
